<?php require admin_tpl('header')?>

<div class="tab">
	<ul>
		<li><a href="?mod=theme&ac=themes"<?php echo $tabon['themes']?>>主题列表</a></li>
		<li><a href="?mod=theme&ac=widgets"<?php echo $tabon['widgets']?>>侧栏工具</a></li>
	</ul>
</div>

<div class="main">
<?php if ( $ac == 'themes' ) { ?>
	<table width="100%">
		<tr>
			<td>
				<?php foreach ($themes as $theme) {?>
				<dl class="theme<?php if ($theme['directory'] == $cur_theme) echo ' theme_current';?>">
					<dt><a href="?mod=theme&ac=settheme&theme=<?php echo $theme['directory']?>" title="应用该主题"><img src="<?php echo $theme['path'].$theme['thumb']?>" /></a></dt>
					<dd class="theme_name"><?php echo $theme['name']?></dd>
					<dd>作者：<?php echo $theme['author']?></dd>
					<dd>版本：<?php echo $theme['version']?></dd>
					<dd>时间：<?php echo $theme['pubdate']?></dd>
					<dd>主页：<a href="<?php echo $theme['homepage']?>" target="_blank"><?php echo $theme['homepage']?></a></dd>
					<dd title="<?php echo $theme['intro']?>">简介：<?php echo cut_str($theme['intro'],60)?></dd>
				</dl>
				<?php }?>
			</td>
		</tr>
	</table>
<?php } elseif ( $ac == 'widgets' ) { ?>

	<div id="activation_widgets">
		<div class="widget_title">已启用</div>
		<?php 
		foreach ( $activation_widgets as $name ) {
			$widget = Widget::factory($name);
		?>
			<form id="widget_<?php echo $name;?>_form">
				<input type="hidden" name="name" value="<?php echo $name;?>" />
				<div class="widget">
					<div class="widget_title">
					<a href="?mod=theme&ac=removewidget&id=<?php echo $name?>" style="float:right">移除</a>
					<?php echo $widget->options['title']?>
					</div>
					<div class="widget_form">
					<div class="widget_setting"><?php echo $widget->setting() ?></div>
					<div class="widget_bottom">
					<label class="widget_tips"></label>
					<input type="button" class="widget_save" value="保存" />
					</div>
					</div>
				</div>
			</form>
		<?php 
		}
		?>
	</div>

	<div id="enabled_widgets">
	<div id="inner_enabled_widgets">
		<div class="widget_title">可用小工具</div>
		<?php
		foreach ( $widgets as $name => $info ) { 
		?>
			<div class="widget">
				<div class="widget_name">
				<?php if ( !in_array($name, $activation_widgets) ) { ?>
				<a href="?mod=theme&ac=addwidget&id=<?php echo $name?>" style="float:right">添加</a>
				<?php }?>
				<?php echo $info['name']?></div>
				<div class="widget_desc"><?php echo $info['description']?></div>
			</div>
			</form>
		<?php } ?>
	</div>
	</div>

<?php } ?>
</div>

<script type="text/javascript">
$( function() {
	$('#activation_widgets .widget .widget_title').each(function() {
		$(this).css('cursor','pointer');
		$(this).click( function() {
			$(this).siblings('.widget_form').toggle();
		});
	});
	$('#activation_widgets .widget_save').each(function(){
		var tips = $(this).siblings('.widget_tips');
		var btn = $(this);
		$(this).click(function() {
			tips.html('<img src="images/loading.gif" />');
			btn.attr('disabled','disabled');
			var data = $(this).parent().parent().parent().parent('form').serialize();
			$.post('admin.php?mod=theme&ac=savewidget', data, function(msg) {
				eval('var msg = '+msg);
				if ( msg.status == 'success' ) {
					tips.html('已保存');
					btn.attr('disabled','');
				}
			});
		});
	});
});
</script>

<?php require admin_tpl('footer')?>